﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Collections;
using Microsoft.VisualBasic;
using System.Data.OleDb;

namespace LCWMS
{
    public partial class w_mst010 : DockContent
    {
        private string str_sql = "";
        private DataSet dscustomer;
        private DataSet dscustomer_area;
        private DataSet dscustomer_location;
        private int coint = 0;
        private string str_area_code = "";

        private bool selectmessage;
        private string str_take_loc;

        public w_mst010()
        {
            InitializeComponent();
            dvg_warehouse.AutoGenerateColumns = false;
            dvg_area.AutoGenerateColumns = false;
            dvg_location.AutoGenerateColumns = false;
        }
        //设置按钮可用和不可用,b_tmp 0说明可以编辑，否处于待保存状态
        private void f_setbutton(bool b_tmp)
        {
            if (b_tmp)//打开窗口
            {
                btn_new.Enabled = true;
                btn_modi.Enabled = true;
                btn_del.Enabled = true;
                dvg_area.Enabled = true;
                dvg_warehouse.Enabled = true;
                dvg_location.Enabled = true;
                btn_save.Enabled = false;
                btn_cancel.Enabled = false;

            }
            else //新增,修改
            {
                btn_new.Enabled = false;
                btn_modi.Enabled = false;
                btn_del.Enabled = false;
                dvg_area.Enabled = false;
                dvg_location.Enabled = false;
                dvg_warehouse.Enabled = false;
                btn_save.Enabled = true;
                btn_cancel.Enabled = true;
            }


        }
        //初始化统计分类1
        private void f_initac1()
        {
            DataSet f_dsc1;
            string str_c1;
            //清空
            cbx_class_code1.Text = "";
            str_c1 = "select class_code from " + main.g_space + ".mst_stat_class  where inv_org = '" + main.g_org + "' and class_flag ='C1' order by class_code ";
            try
            {
                if (main.dbtype == "SQL")
                    f_dsc1 = main.dbservice.Sql_exec_selectsql(str_c1);
                else
                    f_dsc1 = main.dbservice.oracle_exec_selectsql(str_c1);
                DataRow drnew;
                drnew = f_dsc1.Tables[0].NewRow();
                drnew["class_code"] = "";
                f_dsc1.Tables[0].Rows.Add(drnew);
                cbx_class_code1.DataSource = f_dsc1.Tables[0];
                cbx_class_code1.ValueMember = "class_code";
                cbx_class_code1.DisplayMember = "class_code";
                cbx_class_code1.Text = "";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of  Statistic class", main.g_info_dataset) + "!" + ee.ToString());
            }
        }
        //初始化统计分类2
        private void f_initac2()
        {
            DataSet f_dsc2;
            string str_c2;
            //清空
            cbx_class_code2.Text = "";
            str_c2 = "select class_code from " + main.g_space + ".mst_stat_class  where inv_org = '" + main.g_org + "' and class_flag ='C2' order by class_code ";
            try
            {
                if (main.dbtype == "SQL")
                    f_dsc2 = main.dbservice.Sql_exec_selectsql(str_c2);
                else
                    f_dsc2 = main.dbservice.oracle_exec_selectsql(str_c2);
                DataRow drnew;
                drnew = f_dsc2.Tables[0].NewRow();
                drnew["class_code"] = "";
                f_dsc2.Tables[0].Rows.Add(drnew);
                cbx_class_code2.DataSource = f_dsc2.Tables[0];
                cbx_class_code2.ValueMember = "class_code";
                cbx_class_code2.DisplayMember = "class_code";
                cbx_class_code2.Text = "";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of  Statistic class", main.g_info_dataset) + "!" + ee.ToString());
            }
        }
        //初始化统计分类3
        private void f_initac3()
        {
            DataSet f_dsc3;
            string str_c3;
            //清空
            cbx_class_code3.Text = "";
            str_c3 = "select class_code from " + main.g_space + ".mst_stat_class  where inv_org = '" + main.g_org + "' and class_flag ='C3' order by class_code ";
            try
            {
                if (main.dbtype == "SQL")
                    f_dsc3 = main.dbservice.Sql_exec_selectsql(str_c3);
                else
                    f_dsc3 = main.dbservice.oracle_exec_selectsql(str_c3);
                DataRow drnew;
                drnew = f_dsc3.Tables[0].NewRow();
                drnew["class_code"] = "";
                f_dsc3.Tables[0].Rows.Add(drnew);
                cbx_class_code3.DataSource = f_dsc3.Tables[0];
                cbx_class_code3.ValueMember = "class_code";
                cbx_class_code3.DisplayMember = "class_code";
                cbx_class_code3.Text = "";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of  Statistic class", main.g_info_dataset) + "!" + ee.ToString());
            }
        }
        //初始化统计分类4
        private void f_initac4()
        {
            DataSet f_dsc4;
            string str_c4;
            //清空
            cbx_class_code4.Text = "";
            str_c4 = "select class_code from " + main.g_space + ".mst_stat_class  where inv_org = '" + main.g_org + "' and class_flag ='C4' order by class_code ";
            try
            {
                if (main.dbtype == "SQL")
                    f_dsc4 = main.dbservice.Sql_exec_selectsql(str_c4);
                else
                    f_dsc4 = main.dbservice.oracle_exec_selectsql(str_c4);
                DataRow drnew;
                drnew = f_dsc4.Tables[0].NewRow();
                drnew["class_code"] = "";
                f_dsc4.Tables[0].Rows.Add(drnew);
                cbx_class_code4.DataSource = f_dsc4.Tables[0];
                cbx_class_code4.ValueMember = "class_code";
                cbx_class_code4.DisplayMember = "class_code";
                cbx_class_code4.Text = "";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of  Statistic class", main.g_info_dataset) + "!" + ee.ToString());
            }
        }
        //初始化统计分类5
        private void f_initac5()
        {
            DataSet f_dsc5;
            string str_c5;
            //清空
            cbx_class_code5.Text = "";
            str_c5 = "select class_code from " + main.g_space + ".mst_stat_class  where inv_org = '" + main.g_org + "' and class_flag ='C5' order by class_code ";
            try
            {
                if (main.dbtype == "SQL")
                    f_dsc5 = main.dbservice.Sql_exec_selectsql(str_c5);
                else
                    f_dsc5 = main.dbservice.oracle_exec_selectsql(str_c5);
                DataRow drnew;
                drnew = f_dsc5.Tables[0].NewRow();
                drnew["class_code"] = "";
                f_dsc5.Tables[0].Rows.Add(drnew);
                cbx_class_code5.DataSource = f_dsc5.Tables[0];
                cbx_class_code5.ValueMember = "class_code";
                cbx_class_code5.DisplayMember = "class_code";
                cbx_class_code5.Text = "";
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize Information of  Statistic class", main.g_info_dataset) + "!" + ee.ToString());
            }
        }
        public void ClearCntrValue(Control parContainer, bool bol, string edit)
        {
            for (int index = 0; index < parContainer.Controls.Count; index++)
            {
                // 如果是容器类控件，递归调用自己
                if (parContainer.Controls[index].HasChildren)
                {
                    // ClearCntrValue(parContainer.Controls[index]);
                }
                else
                {

                    switch (parContainer.Controls[index].GetType().Name)
                    {

                        case "TextBox":

                            if (edit != "1")
                            {
                                parContainer.Controls[index].Text = "";
                            }

                            if (bol == false)
                                ((TextBox)parContainer.Controls[index]).ReadOnly = true;
                            else
                                ((TextBox)parContainer.Controls[index]).ReadOnly = false;
                            break;
                        case "RadioButton":
                            if (edit != "1")
                                ((RadioButton)(parContainer.Controls[index])).Checked = false;
                            ((RadioButton)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "CheckBox":
                            if (edit != "1")
                                ((CheckBox)(parContainer.Controls[index])).Checked = false;

                            ((CheckBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "ComboBox":
                            if (edit != "1")
                                ((ComboBox)(parContainer.Controls[index])).SelectedIndex = 0;
                            ((ComboBox)(parContainer.Controls[index])).Enabled = bol;
                            break;
                        case "DateTimePicker":
                            if (edit != "1")
                                ((DateTimePicker)(parContainer.Controls[index])).Text = "";
                            ((DateTimePicker)(parContainer.Controls[index])).Enabled = bol;
                            break;
                    }

                }
            }
            if (edit == "1")
            {
                tb_location_code.ReadOnly = true;

                if (cbx_mix_sku.SelectedIndex == 1)
                    this.cbx_mix_lotno.Enabled = true;
                else
                    this.cbx_mix_lotno.Enabled = false;
            }

        }

        private void btn_query_Click(object sender, EventArgs e)
        {
            selectmessage = true;
            //string str_sql_where = " where a.inv_org = '" + main.g_org + "' and a.main_dist<>'D' ";
            string str_sql_where = "";
            if (tb_warehouse_ch.Text.Trim() != "")
            {
                str_sql_where += " and a.warehouse like '%" + tb_warehouse_ch.Text.Trim() + "%' ";

            }
            if (tb_warehouse_name_ch.Text.Trim() != "")
            {
                str_sql_where += " and a.warehouse_name like '%" + tb_warehouse_name_ch.Text.Trim() + "%' ";

            }
            if (tb_area_code.Text.Trim() != "")
            {
                str_sql_where += " and b.area_code like '%" + tb_area_code.Text.Trim() + "%' ";

            }
            if (tb_area_name.Text.Trim() != "")
            {
                str_sql_where += " and b.area_name like '%" + tb_area_name.Text.Trim() + "%' ";

            }
            if (tb_belong_area.Text.Trim() != "")
            {
                str_sql_where += " and b.belong_area like  '%" + tb_belong_area.Text.Trim() + "%' ";
            }
            if (cbx_area_flag.Text.Trim() != "")
            {
                str_sql_where += " and b.area_flag = '" + cbx_area_flag.SelectedIndex.ToString().Trim() + "' ";

            }
            if (tb_loc_code.Text.Trim() != "")
            {
                str_sql_where += " and exists (select 1 from " + main.g_space + ".mst_location e where b.inv_org =e.inv_org and b.area_code = e.area_code and e.location_code like '" + tb_loc_code.Text.Trim() + "%'  )";
            }
            if (tb_standby_4_q.Text.Trim() != "")
            {
                str_sql_where += " and exists (select 1 from " + main.g_space + ".mst_location e where b.inv_org =e.inv_org and b.area_code = e.area_code and e.standby_4 like '" + tb_standby_4_q.Text.Trim() + "%'  )";
            }
            if (tb_standby_5_q.Text.Trim() != "")
            {
                str_sql_where += " and exists (select 1 from " + main.g_space + ".mst_location e where b.inv_org =e.inv_org and b.area_code = e.area_code and e.standby_5 like '" + tb_standby_5_q.Text.Trim() + "%'  )";
            }
            //str_sql="select distinct a.warehouse,a.warehouse_name,a.warehouse_flag from " + main.g_space + ".mst_warehouse a left join " + main.g_space + ".mst_area b on b.inv_org = a.inv_org and b.warehouse=a.warehouse"+str_sql_where;

            try
            {
                if (main.dbtype == "SQL")
                {
                    //str_sql = "select distinct a.warehouse,a.warehouse_name,a.warehouse_flag from " + main.g_space + ".mst_warehouse a," + main.g_space + ".mst_area b," +  //*= 左连接改left join
                    //   " " + main.g_space + ".mst_location c  where a.inv_org = '" + main.g_org + "' and a.main_dist<>'D' and a.inv_org=b.inv_org ";
                    //str_sql += "  and b.inv_org *=c.inv_org and a.warehouse=b.warehouse and b.area_code *= c.area_code  " + str_sql_where + " order by a.warehouse";

                    str_sql = "select distinct a.warehouse,a.warehouse_name,a.warehouse_flag from " + main.g_space + ".mst_warehouse a," + main.g_space + ".mst_area b " +
                              " left join " + main.g_space +".mst_location c   on  b.inv_org =c.inv_org  and b.area_code = c.area_code" +
                              " where a.inv_org = '" + main.g_org + "' and a.main_dist<>'D' and a.inv_org=b.inv_org ";
                    str_sql += " and a.warehouse=b.warehouse " + str_sql_where + " order by a.warehouse";

    
                    dscustomer = main.dbservice.Sql_exec_selectsql(str_sql);
                }
                else
                {
                    str_sql = "select distinct a.warehouse,a.warehouse_name,a.warehouse_flag from " + main.g_space + ".mst_warehouse a," + main.g_space + ".mst_area b," +
                       " " + main.g_space + ".mst_location c  where a.inv_org = '" + main.g_org + "' and a.main_dist<>'D' and a.inv_org=b.inv_org " +
                       "  and b.inv_org =c.inv_org (+) and a.warehouse=b.warehouse and b.area_code = c.area_code (+) " + str_sql_where + " order by a.warehouse";
                    dscustomer = main.dbservice.oracle_exec_selectsql(str_sql);
                }
                dvg_warehouse.DataSource = dscustomer.Tables[0];
                if (dscustomer.Tables[0].Rows.Count > 0)
                {
                    string str_sql_area = "";
                    if (main.dbtype == "SQL")                        //20240919 修改左连接
                    {
                       // str_sql_area = "select distinct a.* from " + main.g_space + ".mst_area a, " + main.g_space + ".mst_location b where a.inv_org = '" + main.g_org + "' and  a.inv_org *= b.inv_org  and a.area_code *= b.area_code  and a.main_dist<>'D'and  a.warehouse='" + dvg_warehouse.Rows[0].Cells["warehouse"].Value.ToString() + "'";

                        str_sql_area = "select distinct a.* from " + main.g_space + ".mst_area a  left join  " + main.g_space + ".mst_location  b  on a.inv_org = b.inv_org  and a.area_code = b.area_code   where a.inv_org = '" + main.g_org + "' and   a.main_dist<>'D'and  a.warehouse='" + dvg_warehouse.Rows[0].Cells["warehouse"].Value.ToString() + "'";
                    }
                    else
                    {
                        str_sql_area = "select distinct a.* from " + main.g_space + ".mst_area a, " + main.g_space + ".mst_location b where a.inv_org = '" + main.g_org + "' and  a.inv_org =b.inv_org (+) and a.area_code = b.area_code (+) and a.main_dist<>'D'and  a.warehouse='" + dvg_warehouse.Rows[0].Cells["warehouse"].Value.ToString() + "'";
                    }
                    if (tb_area_code.Text.Trim() != "")
                    {
                        str_sql_area += " and a.area_code like '%" + tb_area_code.Text.Trim() + "%' ";

                    }
                    if (tb_area_name.Text.Trim() != "")
                    {
                        str_sql_area += " and a.area_name like '%" + tb_area_name.Text.Trim() + "%' ";

                    }
                    if (tb_belong_area.Text.Trim() != "")
                    {
                        str_sql_area += " and a.belong_area like '%" + tb_belong_area.Text.Trim() + "%' ";
                    }
                    if (cbx_area_flag.Text.Trim() != "")
                    {
                        str_sql_area += " and a.area_flag = '" + cbx_area_flag.SelectedIndex.ToString().Trim() + "' ";

                    }
                    if (tb_loc_code.Text.Trim() != "")
                    {
                        //str_sql_area += " and b.location_code like '%" + tb_loc_code.Text.Trim() + "%' ";
                        str_sql_area += " and exists (select 1 from " + main.g_space + ".mst_location e where a.inv_org =e.inv_org and a.area_code = e.area_code and e.location_code like '" + tb_loc_code.Text.Trim() + "%'  )";
                    }
                    if (tb_standby_4_q.Text.Trim() != "")
                    {
                        str_sql_area += " and exists (select 1 from " + main.g_space + ".mst_location e where a.inv_org =e.inv_org and a.area_code = e.area_code and e.standby_4 like '" + tb_standby_4_q.Text.Trim() + "%'  )";
                    }
                    if (tb_standby_5_q.Text.Trim() != "")
                    {
                        str_sql_area += " and exists (select 1 from " + main.g_space + ".mst_location e where a.inv_org =e.inv_org and a.area_code = e.area_code and e.standby_5 like '" + tb_standby_5_q.Text.Trim() + "%'  )";
                    }
                    dscustomer_area = new DataSet();
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            dscustomer_area = main.dbservice.Sql_exec_selectsql(str_sql_area);
                        }
                        else
                        {
                            dscustomer_area = main.dbservice.oracle_exec_selectsql(str_sql_area);
                        }
                        if (dscustomer_area.Tables[0].Rows.Count > 0)
                        {
                            for (int i = 0; i < dscustomer_area.Tables[0].Rows.Count; i++)
                            {
                                switch (dscustomer_area.Tables[0].Rows[i]["area_flag"].ToString().Trim())
                                {
                                    case "0":
                                        dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Stock Area", main.g_info_dataset);
                                        break;
                                    case "1":
                                        dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("PA Area", main.g_info_dataset);
                                        break;
                                    case "2":
                                        dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Picking area", main.g_info_dataset);
                                        break;
                                }
                            }
                        }
                        if (dscustomer_area.Tables[0].Rows.Count > 0)
                        {
                            dvg_area.DataSource = dscustomer_area.Tables[0];
                            string str_sql_location = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " + 
                                " from " + main.g_space + ".mst_location " + 
                                " where inv_org = '" + main.g_org + "' "+ 
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                            if (!cbx_status.Checked) str_sql_location = str_sql_location + " and main_dist<>'D' "; // 勾选显示启用停用

                            if (tb_loc_code.Text.Trim() != "")
                            {
                                str_sql_location += " and location_code like '" + tb_loc_code.Text.Trim() + "%' ";
                            }
                            if (tb_standby_4_q.Text.Trim() != "")
                            {
                                str_sql_location += " and standby_4 like '" + tb_standby_4_q.Text.Trim() + "%' ";
                            }
                            if (tb_standby_5_q.Text.Trim() != "")
                            {
                                str_sql_location += " and standby_5 like '" + tb_standby_5_q.Text.Trim() + "%' ";
                            }
                            dscustomer_location = new DataSet();
                            try
                            {
                                if (main.dbtype == "SQL")
                                {
                                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_location);
                                }
                                else
                                {
                                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_location);
                                }
                                dvg_location.DataSource = dscustomer_location.Tables[0];
                                if (dscustomer_location.Tables[0].Rows.Count > 0)
                                {
                                    show(dscustomer_location.Tables[0].Rows[0]);

                                }
                            }
                            catch (System.Exception ee)
                            {
                                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                                return;
                            }
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of area", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                }
                else
                {
                    dvg_area.DataSource = null;
                    dvg_location.DataSource = null;
                    ClearCntrValue(this.tabPage1, false, "0");
                    ClearCntrValue(this.tabPage2, false, "0");
                }

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to Query", main.g_info_dataset) + "!" + ee.ToString());
            }
        }

        private void show(DataRow tr)
        {
            tb_all_location.Text = tr["location_code"].ToString().Trim();
            tb_location_code.Text = tr["location_code"].ToString().Trim();
            tb_location_order.Text = tr["location_order"].ToString().Trim();

            tb_length.Text = tr["length"].ToString().Trim();
            tb_width.Text = tr["width"].ToString().Trim();
            tb_hight.Text = tr["hight"].ToString().Trim();

            tb_line_number.Text = tr["line_number"].ToString().Trim();
            tb_cubage_limit.Text = tr["cubage_limit"].ToString().Trim();
            tb_weight_limit.Text = tr["weight_limit"].ToString().Trim();

            tb_number_limit.Text = tr["number_limit"].ToString().Trim();
            tb_pallet_number.Text = tr["pallet_number"].ToString().Trim();
            cbx_location_flag.SelectedIndex = Convert.ToInt32(tr["location_flag"]);
            cbx_tax.SelectedIndex = Convert.ToInt32(tr["standby_flag1"]);
            cbx_kind_flag.SelectedIndex = Convert.ToInt32(tr["kind_flag"].ToString().Trim());
            cbx_mix_sku.SelectedIndex = Convert.ToInt32(tr["mix_sku"].ToString().Trim());
            cbx_mix_lotno.SelectedIndex = Convert.ToInt32(tr["mix_lotno"].ToString().Trim());
            cbx_lock_flag.SelectedIndex = Convert.ToInt32(tr["lock_flag"].ToString().Trim());



            tb_attribute1.Text = tr["attribute1"].ToString().Trim();
            tb_attribute2.Text = tr["attribute2"].ToString().Trim();
            tb_attribute3.Text = tr["attribute3"].ToString().Trim();
            tb_attribute4.Text = tr["attribute4"].ToString().Trim();
            tb_attribute5.Text = tr["attribute5"].ToString().Trim();


            this.cbx_class_code1.SelectedValue = tr["class_code1"].ToString().Trim();
            this.cbx_class_code2.SelectedValue = tr["class_code2"].ToString().Trim();
            this.cbx_class_code3.SelectedValue = tr["class_code3"].ToString().Trim();
            this.cbx_class_code4.SelectedValue = tr["class_code4"].ToString().Trim();
            this.cbx_class_code5.SelectedValue = tr["class_code5"].ToString().Trim();

            textBox1.Text = tr["standby_3"].ToString().Trim();
            tb_standby_4.Text = tr["standby_4"].ToString().Trim();
            tb_standby_5.Text = tr["standby_5"].ToString().Trim();

            tb_memo.Text = tr["memo"].ToString().Trim();
            tb_safe_storage.Text = tr["safe_storage"].ToString().Trim();

            if (tr["putaway_flag"].ToString().Trim().ToUpper() == "1")
            {
                cbx_putaway_flag.Text = "YES";
            }
            else
            {
                cbx_putaway_flag.Text = "NO";
            }
            if (tr["alloc_flag"].ToString().Trim().ToUpper() == "1")
            {
                cbx_alloc_flag.Text = "YES";
            }
            else
            {
                cbx_alloc_flag.Text = "NO";
            }
        }
        private void w_mst010_Load(object sender, EventArgs e)
        {
            selectmessage = true;
            DataSet ds_type = new DataSet();
            DataSet ds_class = new DataSet();
            DataSet ds_tax;
            ArrayList al_cbx = new ArrayList();
            int i_cbx;
            string str_common = "";
            //获取按钮权限
            string str_right;

            str_right = main.g_class.comm_getright("w_mst010", main.g_right_dataset);

            //新增
            str_take_loc = "1";
            if (str_right.Substring(0, 1) == "0")
            {
                btn_new.Visible = false;
            }

            else
            {
                btn_new.Visible = true;
            }

            //修改

            if (str_right.Substring(1, 1) == "0")
            {
                btn_modi.Visible = false;
            }

            else
            {
                btn_modi.Visible = true;
            }

            //删除

            if (str_right.Substring(2, 1) == "0")
            {
                btn_del.Visible = false;
            }

            else
            {
                btn_del.Visible = true;
            }

            //保存，取消

            if (str_right.Substring(3, 1) == "0")
            {
                btn_save.Visible = false;
                btn_cancel.Visible = false;
            }
            else
            {
                btn_save.Visible = true;
                btn_cancel.Visible = true;

            }
            if (str_right.Substring(5, 1) == "0")
            {
                btn_file.Visible = false;

            }
            else
            {
                btn_file.Visible = true;

            }
            //得到库位编码的生成方式str_take_loc
            try
            {
                string str_sql2 = "select id_data from " + main.g_space + ".sys_parameter where inv_org='" + main.g_org + "' and id = 8019";
                if (main.dbtype == "SQL")
                {
                    str_take_loc = main.dbservice.Sql_exec_selectstring(str_sql2).Trim();
                }
                else
                {
                    str_take_loc = main.dbservice.oracle_exec_selectstring(str_sql2).Trim();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.ToString());
                return;
            }
            try
            {
                //初始化保税区分
                if (main.dbtype == "SQL")
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then convert(char,number1) else convert(char,number2) end as tax_dist  from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and ltrim(rtrim(dictionary_name))='tax_dist' order by dictionary_code";
                    ds_tax = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then to_char(number1) else to_char(number2) end as tax_dist  from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and trim(dictionary_name)='tax_dist' order by dictionary_code";
                    ds_tax = main.dbservice.oracle_exec_selectsql(str_common);
                }

                cbx_tax.ValueMember = "dictionary_code";
                cbx_tax.DisplayMember = "tax_dist";
                cbx_tax.DataSource = ds_tax.Tables[0].DefaultView;
                cbx_tax.SelectedValue = "0";

                if (main.dbtype == "SQL")
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then convert(char,number1) else convert(char,number2) end as warehouse_flag  from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and ltrim(rtrim(dictionary_name))='warehouse_flag' order by dictionary_code";
                    ds_type = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select dictionary_code,case use_flag when '1' then content1 when '2' then content2 when '3' then to_char(number1) else to_char(number2) end as warehouse_flag  from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and trim(dictionary_name)='warehouse_flag' order by dictionary_code";
                    ds_type = main.dbservice.oracle_exec_selectsql(str_common);
                }

                //取统计分类
                if (main.dbtype == "SQL")
                {
                    str_common = "select class_code,class_name  from " + main.g_space + ".mst_stat_class where inv_org = '" + main.g_org + "' and ltrim(rtrim(class_flag))='class_code' order by class_code";
                    ds_class = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select class_code,class_name  from " + main.g_space + ".mst_stat_class where inv_org = '" + main.g_org + "' and trim(class_flag)='class_code' order by class_code";
                    ds_class = main.dbservice.oracle_exec_selectsql(str_common);
                }
                int j_ds;
                j_ds = ds_class.Tables[0].Rows.Count;
                if (j_ds > 0)
                {
                    for (int j = 0; j < j_ds; j++)
                    {
                        ds_class.Tables[0].Rows[j]["class_code"] = main.g_class.comm_getchangestring(ds_class.Tables[0].Rows[j]["class_code"].ToString().Trim(), main.g_info_dataset);
                        ds_class.Tables[0].Rows[j]["class_name"] = main.g_class.comm_getchangestring(ds_class.Tables[0].Rows[j]["class_code"].ToString().Trim(), main.g_info_dataset);
                    }
                }
                DataRow dj = ds_class.Tables[0].NewRow();
                dj["class_code"] = "";
                dj["class_name"] = "";
                ds_class.Tables[0].Rows.Add(dj);
                cbx_class_code1.DataSource = ds_class.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                cbx_class_code1.DisplayMember = "class_name";
                cbx_class_code1.ValueMember = "class_code";

                DataSet ds_class2 = ds_class.Copy();
                cbx_class_code2.DataSource = ds_class2.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                cbx_class_code2.DisplayMember = "class_name";
                cbx_class_code2.ValueMember = "class_code";
                DataSet ds_class3 = ds_class.Copy();
                cbx_class_code3.DataSource = ds_class3.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                cbx_class_code3.DisplayMember = "class_name";
                cbx_class_code3.ValueMember = "class_code";

                DataSet ds_class4 = ds_class.Copy();
                cbx_class_code4.DataSource = ds_class4.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                cbx_class_code4.DisplayMember = "class_name";
                cbx_class_code4.ValueMember = "class_code";
                DataSet ds_class5 = ds_class.Copy();
                cbx_class_code5.DataSource = ds_class5.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                cbx_class_code5.DisplayMember = "class_name";
                cbx_class_code5.ValueMember = "class_code";


                i_cbx = cbx_location_flag.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cbx_location_flag.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cbx_location_flag.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cbx_location_flag.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cbx_location_flag.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                i_cbx = cbx_kind_flag.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cbx_kind_flag.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cbx_kind_flag.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cbx_kind_flag.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cbx_kind_flag.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                i_cbx = cbx_lock_flag.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cbx_lock_flag.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cbx_lock_flag.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cbx_lock_flag.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cbx_lock_flag.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                i_cbx = cbx_mix_sku.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cbx_mix_sku.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cbx_mix_sku.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cbx_mix_sku.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cbx_mix_sku.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }
                i_cbx = cbx_mix_lotno.Items.Count;
                al_cbx.Clear();
                if (i_cbx > 0)
                {
                    for (int i = 0; i < i_cbx; i++)
                    {
                        if (cbx_mix_lotno.Items[i].ToString().Trim() != "")
                            al_cbx.Add(main.g_class.comm_getchangestring(cbx_mix_lotno.Items[i].ToString().Trim(), main.g_info_dataset));
                    }
                    //清除cbx_bookstatus
                    cbx_mix_lotno.Items.Clear();
                    //在加入
                    i_cbx = al_cbx.Count;
                    for (int i = 0; i < i_cbx; i++)
                    {
                        cbx_mix_lotno.Items.Add(al_cbx[i]);
                    }
                    //出来在加上空值
                    //cbx_bookstatus.Items.Add("");
                }

                //初始化统计分类1-5
                f_initac1();
                f_initac2();
                f_initac3();
                f_initac4();
                f_initac5();
                //初始化按钮
                f_setbutton(true);
                //进行语言转换
                int i_ds;
                i_ds = ds_type.Tables[0].Rows.Count;
                if (i_ds > 0)
                {
                    for (int i = 0; i < i_ds; i++)
                    {
                        ds_type.Tables[0].Rows[i]["warehouse_flag"] = main.g_class.comm_getchangestring(ds_type.Tables[0].Rows[i]["warehouse_flag"].ToString().Trim(), main.g_info_dataset);
                    }
                }
                DataRow dr = ds_type.Tables[0].NewRow();
                dr["dictionary_code"] = "";
                dr["warehouse_flag"] = "";
                ds_type.Tables[0].Rows.Add(dr);
                DataGridViewComboBoxColumn dgvComboBoxColumn = dvg_warehouse.Columns["warehouse_flag"] as DataGridViewComboBoxColumn;
                dgvComboBoxColumn.DisplayMember = "warehouse_flag";
                dgvComboBoxColumn.ValueMember = "dictionary_code";
                dgvComboBoxColumn.DataPropertyName = "warehouse_flag";
                dgvComboBoxColumn.DataSource = ds_type.Tables[0];//必须在设置dataGridView1的DataSource的属性前设置
                main.g_class.comm_changeControl(this, main.g_win_dataset);
                main.g_class.comm_changeCbxContent(cbx_area_flag, main.g_info_dataset, '1');
                cbx_location_flag.SelectedIndex = 0;
                cbx_kind_flag.SelectedIndex = 0;
                cbx_mix_sku.SelectedIndex = 0;
                cbx_mix_lotno.SelectedIndex = 0;
                cbx_lock_flag.SelectedIndex = 0;
                ClearCntrValue(this.tabPage1, false, "0");
                ClearCntrValue(this.tabPage2, false, "0");

                // 在绑定数据后添加这个事件处理程序
                //dvg_location.CellFormatting += DgLocation_CellFormatting; // 画背景色

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to initialize differentiation of warehouse", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        

        private void dvg_warehouse_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) return;
            string str_sql_area = "select * from " + main.g_space + ".mst_area where inv_org = '" + main.g_org + "' and main_dist<>'D'and  warehouse='" + dvg_warehouse.Rows[dvg_warehouse.CurrentRow.Index].Cells["warehouse"].Value.ToString() + "'";
            dscustomer_area = new DataSet();
            try
            {
                if (main.dbtype == "SQL")
                {
                    dscustomer_area = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    dscustomer_area = main.dbservice.oracle_exec_selectsql(str_sql_area);
                }
                if (dscustomer_area.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dscustomer_area.Tables[0].Rows.Count; i++)
                    {
                        switch (dscustomer_area.Tables[0].Rows[i]["area_flag"].ToString().Trim())
                        {
                            case "0":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Stock area", main.g_info_dataset);
                                break;
                            case "1":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("PA Area", main.g_info_dataset);
                                break;
                            case "2":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Picking Area", main.g_info_dataset);
                                break;
                        }
                    }
                }
                dvg_area.DataSource = dscustomer_area.Tables[0];
                if (dscustomer_area.Tables[0].Rows.Count > 0)
                {
                    //str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and  area_code='" + dscustomer_area.Tables[0].Rows[0]["area_code"].ToString().Trim() + "'";
                    str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                    if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用

                    dscustomer_location = new DataSet();
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                        }
                        else
                        {
                            dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);
                        }
                        dvg_location.DataSource = dscustomer_location.Tables[0];
                        if (dscustomer_location.Tables[0].Rows.Count > 0)
                        {
                            DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                            if (tr.Length > 0)
                                show(tr[0]);
                        }
                        else
                        {
                            dvg_location.DataSource = dscustomer_location.Tables[0];
                            ClearCntrValue(this.tabPage1, false, "0");
                            ClearCntrValue(this.tabPage2, false, "0");
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                }
                else
                {
                    dvg_location.DataSource = null;
                    ClearCntrValue(this.tabPage1, false, "0");
                    ClearCntrValue(this.tabPage2, false, "0");
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void dvg_area_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            str_area_code = dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString().Trim();
            //string str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString().Trim() + "'";
            string str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
            if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用

            dscustomer_location = new DataSet();
            try
            {
                if (main.dbtype == "SQL")
                {
                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);
                }
                dvg_location.DataSource = dscustomer_location.Tables[0];
                if (dscustomer_location.Tables[0].Rows.Count > 0)
                {
                    DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                    if (tr.Length > 0)
                        show(tr[0]);
                }
                else
                {
                    ClearCntrValue(this.tabPage1, false, "0");
                    ClearCntrValue(this.tabPage2, false, "0");
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void cbx_mix_sku_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbx_mix_sku.SelectedIndex == 1)
                this.cbx_mix_lotno.Enabled = true;
        }

        private void btn_new_Click(object sender, EventArgs e)
        {
            if (dvg_area.Rows.Count <= 0)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("no area", main.g_info_dataset) + "!");
                return;
            }
            coint = 1;
            //初始化按钮
            f_setbutton(false);
            ClearCntrValue(this.tabPage1, true, "0");
            ClearCntrValue(this.tabPage2, true, "0");
            ClearCntrValue(this.groupBox1, true, "0");
            cbx_tax.Enabled = false;
            cbx_mix_lotno.Text = "Yes";
            cbx_mix_sku.Text = "Yes";
            cbx_kind_flag.SelectedIndex = 2;

            cbx_class_code1.Text = "";
            cbx_class_code2.Text = "";
            cbx_class_code3.Text = "";

            // 初始化默认值
            tb_location_order.Text = "0";
            tb_length.Text = "0";
            tb_width.Text = "0";
            tb_hight.Text = "0";
            tb_line_number.Text = "1"; // 排数量
            tb_number_limit.Text = "10000"; // 数量数量
            tb_pallet_number.Text = "1"; // 托盘数限制
            tb_cubage_limit.Text = "1"; // 体积限制
            tb_weight_limit.Text = "1"; // 重量限制

            tb_safe_storage.Text = "0"; // 安全库存
            textBox1.Text = "00" ;// 备用

            try
            {
                DataSet ds_temp;
                if (dvg_warehouse.SelectedRows.Count > 0)
                {
                    string str_sql = "select warehouse_flag,putaway_flag,alloc_flag from " + main.g_space + ".mst_warehouse where inv_org='" + main.g_org + "' and warehouse='" + dvg_warehouse.SelectedRows[0].Cells[0].Value.ToString().Trim() + "'";
                    if (main.dbtype == "SQL")
                    {
                        ds_temp = main.dbservice.Sql_exec_selectsql(str_sql);
                    }
                    else
                    {
                        ds_temp = main.dbservice.oracle_exec_selectsql(str_sql);
                    }
                    if (ds_temp.Tables[0].Rows.Count > 0)
                    {
                        cbx_tax.SelectedValue = ds_temp.Tables[0].Rows[0]["warehouse_flag"].ToString().Trim();
                        //str_putaway_flag = ds_temp.Tables[0].Rows[0]["putaway_flag"].ToString().Trim();
                        //str_alloc_flag = ds_temp.Tables[0].Rows[0]["alloc_flag"].ToString().Trim();
                    }
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show("获取仓库报税区分失败" + ee.Message);
            }
        }

        private void btn_modi_Click(object sender, EventArgs e)
        {
            if (tb_location_code.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个库位才能修改！");
                return;
            }
            coint = 2;
            //初始化按钮
            f_setbutton(false);

            ClearCntrValue(this.tabPage1, true, "1");
            ClearCntrValue(this.tabPage2, true, "1");
            cbx_tax.Enabled = false;

        }

        private void btn_del_Click(object sender, EventArgs e)
        {
            dscustomer_location = new DataSet();
            string str_temp = "";
            string str_sql = "";
            if (tb_location_code.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个要停用的库位！");
                return;
            }
            if (MessageBox.Show("确认停用 " + tb_location_code.Text.Trim() + " ?", main.g_class.comm_getchangestring("Information", main.g_info_dataset), MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }
            if (main.dbtype == "SQL")
            {
                str_temp = str_temp + "update_time=getdate(),";
            }
            else
            {
                str_temp = str_temp + "update_time= sysdate,";
            }
            str_temp = str_temp + "updater='" + main.g_user + "' where inv_org = '" + main.g_org + "' and location_code='" + tb_location_code.Text.Trim() + "'";
            str_sql = "update " + main.g_space + ".mst_location  set main_dist='D'," + str_temp;
            try
            {
                //string str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and  area_code='" + str_area_code + "'";
                string str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用
                if (main.dbtype == "SQL")
                {
                    main.dbservice.Sql_exec_commandsql(str_sql);
                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    main.dbservice.oracle_exec_commandsql(str_sql);
                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);

                }

                dvg_location.DataSource = dscustomer_location.Tables[0];
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to save!", main.g_info_dataset) + "!" + ee.ToString());
                Cursor.Current = Cursors.Default;
                return;
            }
            //刷新信息
            btn_query_Click(sender, new EventArgs());
        }

        private void btn_open_Click(object sender, EventArgs e)
        {
            dscustomer_location = new DataSet();
            string str_temp = "";
            string str_sql = "";
            if (tb_location_code.Text.Trim() == "")
            {
                MessageBox.Show("必须选择一个要启用的库位！");
                return;
            }
            if (MessageBox.Show("确认启用 " + tb_location_code.Text.Trim() + " ?", main.g_class.comm_getchangestring("Information", main.g_info_dataset), MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }
            if (main.dbtype == "SQL")
            {
                str_temp = str_temp + "update_time=getdate(),";
            }
            else
            {
                str_temp = str_temp + "update_time= sysdate,";
            }
            str_temp = str_temp + "updater='" + main.g_user + "' where inv_org = '" + main.g_org + "' and location_code='" + tb_location_code.Text.Trim() + "'";
            str_sql = "update " + main.g_space + ".mst_location  set main_dist='A'," + str_temp;
            try
            {
                //string str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and  area_code='" + str_area_code + "'";
                string str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用

                if (main.dbtype == "SQL")
                {
                    main.dbservice.Sql_exec_commandsql(str_sql);
                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    main.dbservice.oracle_exec_commandsql(str_sql);
                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);

                }

                dvg_location.DataSource = dscustomer_location.Tables[0];
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to save!", main.g_info_dataset) + "!" + ee.ToString());
                Cursor.Current = Cursors.Default;
                return;
            }
            //刷新信息
            btn_query_Click(sender, new EventArgs());
        }

        public Decimal gfcInt32(string theObject)
        {
            if (Microsoft.VisualBasic.Information.IsNumeric(theObject.ToString()) == false || theObject.ToString().Trim() == "" || theObject.ToString().Trim() == null || theObject.ToString().Trim() == "undefined")
            {
                return 0;
            }
            try
            {
                return Convert.ToDecimal(theObject);
            }
            catch
            {
                return 0;
            }
        }

        private void btn_save_Click(object sender, EventArgs e)
        {

            str_area_code = dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString().Trim();
            string str_temp = "", str_kind = "";
            decimal d_safe_storage = 0;
            string str_get_newloc = "";
            string str_putaway_flag = "";
            string str_alloc_flag = "";
            if (tb_location_code.Text.Trim() == "")
            {
                MessageBox.Show("库位编码不能为空!");
                tb_location_code.Focus();
                return;
            }
            if (tb_safe_storage.Text.Trim() == "")
            {
                d_safe_storage = 0;
            }
            else
            {
                d_safe_storage = Convert.ToDecimal(tb_safe_storage.Text.Trim());
            }
            str_kind = main.g_class.comm_getconversestring(cbx_kind_flag.Text.Trim(), main.g_info_dataset);
            if (str_kind.Trim().ToLower() == "stack")
            {
                if (tb_number_limit.Text.Trim() == "")
                {
                    MessageBox.Show("必须输入数量限制");
                    tb_number_limit.Focus();
                    return;
                }
                if (tb_number_limit.Text.Trim() == "0")
                {
                    tb_number_limit.Text = "1";
                }
            }
            else
            {
                if (tb_line_number.Text.Trim() == "")
                {
                    MessageBox.Show("必须输入排数量！");
                    tb_line_number.Focus();
                    return;
                }
                if (tb_line_number.Text.Trim() == "0")
                {
                    tb_line_number.Text = "1";
                }
                else if (tb_pallet_number.Text.Trim() == "")
                {
                    MessageBox.Show("必须输入托盘数限制！");
                    tb_pallet_number.Focus();
                    return;
                }
                if (tb_pallet_number.Text.Trim() == "0")
                {
                    tb_pallet_number.Text = "1";
                }
            }
            if (cbx_putaway_flag.Text.Trim().ToUpper() == "YES")
            {
                str_putaway_flag = "1";
            }
            else
            {
                str_putaway_flag = "0";
            }
            if (cbx_alloc_flag.Text.Trim().ToUpper() == "YES")
            {
                str_alloc_flag = "1";
            }
            else
            {
                str_alloc_flag = "0";
            }
            //if (cbx_kind_flag.SelectedIndex.ToString().Trim() != "")
            //{
            //    if (cbx_kind_flag.SelectedIndex == 0 || cbx_kind_flag.SelectedIndex == 1)
            //    {

            //    }
            //}
            if (coint == 1)
            {
                if (str_take_loc.Trim() == "0") //不需要前缀
                {
                    str_get_newloc = tb_location_code.Text.Trim().ToUpper();
                }
                else  //需要前缀
                {
                    str_get_newloc = str_area_code + tb_location_code.Text.Trim().ToUpper();
                }
                string str_pk = "select count(*) from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and location_code='" + str_get_newloc.Trim() + "'";
                str_sql = "insert into " + main.g_space + ".mst_location (" +
                    "inv_org,location_code,area_code,location_order,length,width,hight," +
                    "line_number,cubage_limit,weight_limit,number_limit,pallet_number," +
                    "location_flag,kind_flag,lock_flag,mix_sku,mix_lotno," +
                    "attribute1,attribute2,attribute3,attribute4,attribute5," +
                    "class_code1,class_code2,class_code3,class_code4,class_code5,memo,main_dist,made_time,maker,standby_flag1,putaway_flag,alloc_flag,safe_storage,standby_3,standby_4,standby_5) values (" +
                    "'" + main.g_org + "','" + str_get_newloc.Trim() + "','" + str_area_code + "','" + gfcInt32(tb_location_order.Text.Trim()) + "'," + gfcInt32(tb_length.Text.Trim()) + "," + gfcInt32(tb_width.Text.Trim()) + "," + gfcInt32(tb_hight.Text.Trim()) +
                    "," + gfcInt32(tb_line_number.Text.Trim()) + "," + gfcInt32(tb_cubage_limit.Text.Trim()) + "," + gfcInt32(tb_weight_limit.Text.Trim()) + "," + gfcInt32(tb_number_limit.Text.Trim()) + "," + gfcInt32(tb_pallet_number.Text.Trim()) +
                    ",'" + cbx_location_flag.SelectedIndex + "','" + cbx_kind_flag.SelectedIndex + "','" + cbx_lock_flag.SelectedIndex + "','" + cbx_mix_sku.SelectedIndex + "','" + cbx_mix_lotno.SelectedIndex +
                    "','" + tb_attribute1.Text.Trim() + "','" + tb_attribute2.Text.Trim() + "','" + tb_attribute3.Text.Trim() + "','" + tb_attribute4.Text.Trim() + "','" + tb_attribute5.Text.Trim() +
                    "','" + cbx_class_code1.SelectedValue.ToString().Trim() + "','" + cbx_class_code2.SelectedValue.ToString().Trim() + "','" + cbx_class_code3.SelectedValue.ToString().Trim() + "','" + cbx_class_code4.SelectedValue.ToString().Trim() + "','" + cbx_class_code5.SelectedValue.ToString().Trim() + "','" + tb_memo.Text.Trim() + "','A',";
                int dount = -1;
                if (main.dbtype == "SQL")
                {
                    dount = main.dbservice.Sql_exec_selectint(str_pk);
                    str_temp = str_temp + "getdate(),'";
                }
                else
                {
                    dount = main.dbservice.oracle_exec_selectint(str_pk);
                    str_temp = str_temp + " sysdate,'";
                }
                if (dount > 0)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("The location has already exists", main.g_info_dataset) + "!");
                    this.tb_location_code.Focus();
                    return;
                }
                str_temp = str_temp + main.g_user + "','" + cbx_tax.SelectedValue.ToString().Trim() + "','" + str_putaway_flag + "','" + str_alloc_flag + "'," + d_safe_storage + ",'" + textBox1.Text.Trim() + "','" + tb_standby_4.Text.Trim() + "','" + tb_standby_5.Text.Trim() + "')";
                try
                {
                    str_sql += str_temp;
                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                    // btn_query_Click(sender, new EventArgs());

                    DataRow newdr = ((DataTable)dvg_location.DataSource).NewRow();
                    newdr["location_code"] = str_get_newloc.Trim();

                    ((DataTable)dvg_location.DataSource).Rows.Add(newdr);

                    //dvg_location.CurrentCell = dvg_location.Rows[dvg_location.RowCount - 1].Cells[0];


                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save", main.g_info_dataset) + "!" + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            else if (coint == 2)
            {
                if (main.dbtype == "SQL")
                {
                    str_temp = str_temp + "update_time=getdate(),";
                }
                else
                {
                    str_temp = str_temp + "update_time= sysdate,";
                }
                str_temp = str_temp + "updater='" + main.g_user + "' where inv_org = '" + main.g_org + "' and location_code='" + tb_location_code.Text.Trim() + "'";
                str_sql = "update " + main.g_space + ".mst_location  set location_order='" + tb_location_order.Text.Trim() + "',length=" + gfcInt32(tb_length.Text.Trim()) + ",width=" + gfcInt32(tb_width.Text.Trim()) + ",hight=" + gfcInt32(tb_hight.Text.Trim()) +
               ",line_number=" + gfcInt32(tb_line_number.Text.Trim()) + ",cubage_limit=" + gfcInt32(tb_cubage_limit.Text.Trim()) + ",weight_limit=" + gfcInt32(tb_weight_limit.Text.Trim()) + ",number_limit=" + gfcInt32(tb_number_limit.Text.Trim()) + ",pallet_number=" + gfcInt32(tb_pallet_number.Text.Trim()) +
               ",location_flag='" + cbx_location_flag.SelectedIndex + "',standby_flag1='" + cbx_tax.SelectedValue.ToString().Trim() + "',kind_flag='" + cbx_kind_flag.SelectedIndex + "',lock_flag='" + cbx_lock_flag.SelectedIndex + "',mix_sku='" + cbx_mix_sku.SelectedIndex + "',mix_lotno='" + cbx_mix_lotno.SelectedIndex +
               "',attribute1='" + tb_attribute1.Text.Trim() + "',attribute2='" + tb_attribute2.Text.Trim() + "',attribute3='" + tb_attribute3.Text.Trim() + "',attribute4='" + tb_attribute4.Text.Trim() + "',attribute5='" + tb_attribute5.Text.Trim() + "',standby_3 = '" + textBox1.Text.Trim() +
                "',class_code1='" + cbx_class_code1.SelectedValue.ToString().Trim() + "',class_code2='" + cbx_class_code2.SelectedValue.ToString().Trim() + "',class_code3='" + cbx_class_code3.SelectedValue.ToString().Trim() + "',class_code4='" + cbx_class_code4.SelectedValue.ToString().Trim() + "',class_code5='" + cbx_class_code4.SelectedValue.ToString().Trim() + "',main_dist='U',safe_storage=" + d_safe_storage + ",standby_4='" + tb_standby_4.Text.Trim() + "',standby_5='" + tb_standby_5.Text.Trim() + "',putaway_flag='" + str_putaway_flag + "',alloc_flag='"+str_alloc_flag+"'," + str_temp;
                try
                {

                    if (main.dbtype == "SQL")
                    {
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save", main.g_info_dataset) + "!" + ee.ToString());
                    Cursor.Current = Cursors.Default;
                    return;
                }
            }
            try
            {
                //string str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and  area_code='" + str_area_code + "'";
                string str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用
                if (main.dbtype == "SQL")
                {
                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);
                }

                //dvg_location.DataSource = dscustomer_location.Tables[0];
                //dvg_location.Rows[dvg_location.CurrentRow.Index].Selected = false;
                //dvg_location.Rows[dvg_location.RowCount - 1].Selected = true;
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to save", main.g_info_dataset) + "!" + ee.ToString());
                Cursor.Current = Cursors.Default;
                return;
            }
            if (coint == 1)
            {
                //选中这一行

                for (int i = 0; i < dvg_location.Rows.Count; i++)
                {
                    dvg_location.Rows[i].Selected = false;
                }
                selectmessage = false;
                dvg_location.Rows[dvg_location.RowCount - 1].Selected = true;
            }
            //初始化按钮
            f_setbutton(true);
            ClearCntrValue(this.tabPage1, false, "1");
            ClearCntrValue(this.tabPage2, false, "1");
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            //初始化按钮
            f_setbutton(true);
            ClearCntrValue(this.tabPage1, false, "1");
            ClearCntrValue(this.tabPage2, false, "1");
        }

        private void dvg_location_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dscustomer_location.Tables[0].Rows.Count > 0)
            {
                DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                if (tr.Length > 0)
                    show(tr[0]);
            }
        }

        private void cbx_mix_lotno_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbx_mix_lotno.SelectedIndex == 1)  //
                this.cbx_mix_sku.Enabled = true;
            else
            {
                this.cbx_mix_sku.Enabled = false;
                cbx_mix_sku.SelectedIndex = cbx_mix_lotno.SelectedIndex;
            }
        }

        private void dvg_warehouse_SelectionChanged(object sender, EventArgs e)
        {
            if (dvg_warehouse.CurrentRow == null)
            {
                return;
            }
            string str_sql_area = "select * from " + main.g_space + ".mst_area where inv_org = '" + main.g_org + "' and main_dist<>'D'and  warehouse='" + dvg_warehouse.Rows[dvg_warehouse.CurrentRow.Index].Cells["warehouse"].Value.ToString() + "'";
            dscustomer_area = new DataSet();
            try
            {
                if (main.dbtype == "SQL")
                {
                    dscustomer_area = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    dscustomer_area = main.dbservice.oracle_exec_selectsql(str_sql_area);
                }
                if (dscustomer_area.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dscustomer_area.Tables[0].Rows.Count; i++)
                    {
                        switch (dscustomer_area.Tables[0].Rows[i]["area_flag"].ToString().Trim())
                        {
                            case "0":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Stock area", main.g_info_dataset);
                                break;
                            case "1":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("PA Area", main.g_info_dataset);
                                break;
                            case "2":
                                dscustomer_area.Tables[0].Rows[i]["area_flag"] = main.g_class.comm_getchangestring("Picking Area", main.g_info_dataset);
                                break;
                        }
                    }
                }
                dvg_area.DataSource = dscustomer_area.Tables[0];
                if (dscustomer_area.Tables[0].Rows.Count > 0)
                {
                    //str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and  area_code='" + dscustomer_area.Tables[0].Rows[0]["area_code"].ToString().Trim() + "'";
                    str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
                    if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用
                    dscustomer_location = new DataSet();
                    try
                    {
                        if (main.dbtype == "SQL")
                        {
                            dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                        }
                        else
                        {
                            dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);
                        }
                        dvg_location.DataSource = dscustomer_location.Tables[0];
                        if (dscustomer_location.Tables[0].Rows.Count > 0)
                        {
                            DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                            if (tr.Length > 0)
                                show(tr[0]);
                        }
                        else
                        {
                            dvg_location.DataSource = dscustomer_location.Tables[0];
                            ClearCntrValue(this.tabPage1, false, "0");
                            ClearCntrValue(this.tabPage2, false, "0");
                        }
                    }
                    catch (System.Exception ee)
                    {
                        MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                        return;
                    }
                }
                else
                {
                    dvg_location.DataSource = null;
                    ClearCntrValue(this.tabPage1, false, "0");
                    ClearCntrValue(this.tabPage2, false, "0");
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void dvg_area_SelectionChanged(object sender, EventArgs e)
        {
            if (dvg_area.CurrentRow == null)
            {
                return;
            }
            str_area_code = dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString().Trim();
            //string str_sql_area = "select * from " + main.g_space + ".mst_location where inv_org = '" + main.g_org + "' and main_dist<>'D'and area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString().Trim() + "'";
            string str_sql_area = "select *, case when main_dist <>'D' then '启用' when main_dist = 'D' then '停用' end as status_name " +
                                " from " + main.g_space + ".mst_location " +
                                " where inv_org = '" + main.g_org + "' " +
                                " and  area_code='" + dvg_area.Rows[dvg_area.CurrentRow.Index].Cells["area_code"].Value.ToString() + "'";
            if (!cbx_status.Checked) str_sql_area = str_sql_area + " and main_dist<>'D' "; // 勾选显示启用停用
            dscustomer_location = new DataSet();
            try
            {
                if (main.dbtype == "SQL")
                {
                    dscustomer_location = main.dbservice.Sql_exec_selectsql(str_sql_area);
                }
                else
                {
                    dscustomer_location = main.dbservice.oracle_exec_selectsql(str_sql_area);
                }
                dvg_location.DataSource = dscustomer_location.Tables[0];
                if (dscustomer_location.Tables[0].Rows.Count > 0)
                {
                    DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                    if (tr.Length > 0)
                        show(tr[0]);
                }
                else
                {
                    ClearCntrValue(this.tabPage1, false, "0");
                    ClearCntrValue(this.tabPage2, false, "0");
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Information of location", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }
        }

        private void dvg_location_SelectionChanged(object sender, EventArgs e)
        {
            if (dvg_location.CurrentRow == null)
            {
                return;
            }
            if (dscustomer_location.Tables[0].Rows.Count > 0 && selectmessage == true)
            {
                DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.CurrentRow.Index].Cells["location_code"].Value.ToString() + "'");
                if (tr.Length > 0)
                    show(tr[0]);
            }
            else if (dscustomer_location.Tables[0].Rows.Count > 0 && selectmessage == false)
            {
                DataRow[] tr = dscustomer_location.Tables[0].Select("location_code='" + dvg_location.Rows[dvg_location.Rows.Count - 1].Cells["location_code"].Value.ToString() + "'");
                if (tr.Length > 0)
                    show(tr[0]);
                selectmessage = true;
            }
        }

        private void cbx_area_flag_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btn_file_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Excel文件";
            ofd.FileName = "";
            //ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//为了获取特定的系统文件夹，可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举，其中可以定义要返回路径的哪个系统目录
            ofd.Filter = "Excel文件(*.xls)|*.xls";
            ofd.ValidateNames = true;     //文件有效性验证ValidateNames，验证用户输入是否是一个有效的Windows文件名
            ofd.CheckFileExists = true;  //验证路径有效性
            ofd.CheckPathExists = true; //验证文件有效性

            string strName = string.Empty;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                strName = ofd.FileName;
            }

            if (strName == "")
            {
                MessageBox.Show("没有选择Excel文件！无法进行数据导入");
                return;
            }
            tb_file.Text = strName;
            GetDataFromExcelWithAppointSheetName(strName);
        }
        ///根据excel的文件的路径提取其中表的数据
        ///</summary>
        ///<paramname="Path">Excel文件的路径</param>
        private void GetDataFromExcelWithAppointSheetName(string Path)
        {
            //连接串
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + Path + ";Extended Properties ='Excel 8.0;HDR=YES;IMEX=1'";//导入时包含Excel中的第一行数据，并且将数字和字符混合的单元格视为文本进行导入
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();

            //返回Excel的架构，包括各个sheet表的名称,类型，创建时间和修改时间等　
            DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
            //包含excel中表名的字符串数组
            string[] strTableNames = new string[dtSheetName.Rows.Count];

            for (int k = 0; k < dtSheetName.Rows.Count; k++)
            {
                strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
                //cbx_file.Items.Add(strTableNames[k].Substring(0, strTableNames[k].Length - 1));
            }
            //int i = dtSheetName.Rows.Count - 1;
            //cbx_file.Text = strTableNames[i].Substring(0, strTableNames[i].Length - 1);
            OleDbDataAdapter myCommand = null;
            DataTable dt = new DataTable();

            //从指定的表明查询数据,可先把所有表明列出来供用户选择

            string strExcel = "select*from[" + strTableNames[0] + "]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            dt = new DataTable();
            myCommand.Fill(dt);
            conn.Close();

            if (dt.Rows.Count <= 0)
            {
                return;
            }
            string str_sql = "", str_warehouse = "", str_area_code = "";
            ArrayList al = new ArrayList();
            int i_coun = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                try
                {

                    if (str_warehouse.IndexOf(dt.Rows[i]["仓库号"].ToString().Trim()) < 0)
                    {
                        #region   判断仓库是否存在
                        str_sql = "select count(*) from " + main.g_space + ".mst_warehouse where inv_org='" + main.g_org + "' and warehouse='" + dt.Rows[i]["仓库号"].ToString().Trim() + "' ";
                        if (main.dbtype == "SQL")
                        {
                            i_coun = main.dbservice.Sql_exec_selectint(str_sql);
                        }
                        else
                        {
                            i_coun = main.dbservice.oracle_exec_selectint(str_sql);
                        }
                        if (i_coun <= 0)//仓库不存在
                        {

                            #region 插入仓库
                            str_sql = "insert into  " + main.g_space + ".mst_warehouse (" +
                                   "inv_org,warehouse,warehouse_name,warehouse_flag,memo,main_dist,putaway_flag,alloc_flag,made_time,maker) values(" +
                     "'" + main.g_org + "','" + dt.Rows[i]["仓库号"].ToString().Trim() + "','" + dt.Rows[i]["仓库名称"].ToString().Trim() + "','0','','A','1','1',";
                            if (main.dbtype == "SQL")
                            {
                                str_sql = str_sql + "getdate(),'" + main.g_user + "')";
                            }
                            else
                            {
                                str_sql = str_sql + " sysdate,'" + main.g_user + "')";
                            }
                            al.Add(str_sql);
                            #endregion
                            str_warehouse += dt.Rows[i]["仓库号"].ToString().Trim() + ",";
                            #region  插入区域
                            str_sql = "insert into  " + main.g_space + ".mst_area (inv_org,area_code,belong_area,warehouse,area_name,area_flag, " +
                               "standby_1,standby_2,standby_3,standby_4,memo,main_dist,made_time,maker) values(" +
                 "'" + main.g_org + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','" + dt.Rows[i]["仓库号"].ToString().Trim() + "'," +
                 "'" + dt.Rows[i]["区域名称"].ToString().Trim() + "','0',0,0," +
                 "'','','','A',";
                            if (main.dbtype == "SQL")
                            {
                                str_sql = str_sql + "getdate(),'";
                            }
                            else
                            {
                                str_sql = str_sql + " sysdate,'";
                            }

                            str_sql = str_sql + main.g_user + "')";
                            al.Add(str_sql);
                            str_area_code += dt.Rows[i]["区域号"].ToString().Trim() + ",";
                            #endregion

                            #region 插入库位
                            str_sql = "insert into " + main.g_space + ".mst_location (" +
                      "inv_org,location_code,area_code,location_order,length,width,hight," +
                      "line_number,cubage_limit,weight_limit,number_limit,pallet_number," +
                      "location_flag,kind_flag,lock_flag,mix_sku,mix_lotno," +
                      "attribute1,attribute2,attribute3,attribute4,attribute5," +
                      "class_code1,class_code2,class_code3,class_code4,class_code5,memo,main_dist,made_time,maker,standby_flag1,putaway_flag,alloc_flag,safe_storage,standby_3) values (" +
                      "'" + main.g_org + "','" + dt.Rows[i]["库位号"].ToString().Trim() + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','0',0,0,0,"
                      + "0,0,0,10000000,1" +
                      ",'0','2','0','1','1',''" +
                          ",'','','',''," +
                          "'" + ((DataTable)cbx_class_code1.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code2.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code3.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code4.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code5.DataSource).Rows[0]["class_code"].ToString().Trim() + "','','A',";

                            if (main.dbtype == "SQL")
                            {
                                str_sql = str_sql + "getdate(),'";
                            }
                            else
                            {
                                str_sql = str_sql + " sysdate,'";
                            }

                            str_sql = str_sql + main.g_user + "','0','1','1',0,'')";
                            al.Add(str_sql);
                            #endregion
                            continue;
                        }
                        #endregion
                    }
                    if (str_area_code.IndexOf(dt.Rows[i]["区域号"].ToString().Trim()) < 0)
                    {
                        #region 判断区域是否存在
                        str_sql = "select count(*) from " + main.g_space + ".mst_area where inv_org='" + main.g_org + "' and area_code='" + dt.Rows[i]["区域号"].ToString().Trim() + "' and warehouse='" + dt.Rows[i]["仓库号"].ToString().Trim() + "'";

                        if (main.dbtype == "SQL")
                        {
                            i_coun = main.dbservice.Sql_exec_selectint(str_sql);
                        }
                        else
                        {
                            i_coun = main.dbservice.oracle_exec_selectint(str_sql);
                        }
                        if (i_coun <= 0)//仓库不存在
                        {
                            #region  插入区域
                            str_sql = "insert into  " + main.g_space + ".mst_area (inv_org,area_code,belong_area,warehouse,area_name,area_flag, " +
                               "standby_1,standby_2,standby_3,standby_4,memo,main_dist,made_time,maker) values(" +
                 "'" + main.g_org + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','" + dt.Rows[i]["仓库号"].ToString().Trim() + "'," +
                 "'" + dt.Rows[i]["区域名称"].ToString().Trim() + "','0',0,0," +
                 "'','','','A',";
                            if (main.dbtype == "SQL")
                            {
                                str_sql = str_sql + "getdate(),'";
                            }
                            else
                            {
                                str_sql = str_sql + " sysdate,'";
                            }

                            str_sql = str_sql + main.g_user + "')";
                            al.Add(str_sql);
                            str_area_code += dt.Rows[i]["区域号"].ToString().Trim() + ",";
                            #endregion

                            #region 插入库位
                            str_sql = "insert into " + main.g_space + ".mst_location (" +
                      "inv_org,location_code,area_code,location_order,length,width,hight," +
                      "line_number,cubage_limit,weight_limit,number_limit,pallet_number," +
                      "location_flag,kind_flag,lock_flag,mix_sku,mix_lotno," +
                      "attribute1,attribute2,attribute3,attribute4,attribute5," +
                      "class_code1,class_code2,class_code3,class_code4,class_code5,memo,main_dist,made_time,maker,standby_flag1,putaway_flag,alloc_flag,safe_storage,standby_3) values (" +
                      "'" + main.g_org + "','" + dt.Rows[i]["库位号"].ToString().Trim() + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','0',0,0,0,"
                      + "0,0,0,10000000,1" +
                      ",'0','2','0','1','1',''" +
                          ",'','','',''," +
                          "'" + ((DataTable)cbx_class_code1.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code2.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code3.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code4.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                          ((DataTable)cbx_class_code5.DataSource).Rows[0]["class_code"].ToString().Trim() + "','','A',";

                            if (main.dbtype == "SQL")
                            {
                                str_sql = str_sql + "getdate(),'";
                            }
                            else
                            {
                                str_sql = str_sql + " sysdate,'";
                            }

                            str_sql = str_sql + main.g_user + "','0','1','1',0,'')";
                            al.Add(str_sql);
                            #endregion
                            continue;
                        }
                        #endregion
                    }

                    #region 判断区域是否存在
                    str_sql = "select count(*) from " + main.g_space + ".mst_location where inv_org='" + main.g_org + "' and area_code='" + dt.Rows[i]["区域号"].ToString().Trim() + "' and location_code='" + dt.Rows[i]["库位号"].ToString().Trim() + "'";

                    if (main.dbtype == "SQL")
                    {
                        i_coun = main.dbservice.Sql_exec_selectint(str_sql);
                    }
                    else
                    {
                        i_coun = main.dbservice.oracle_exec_selectint(str_sql);
                    }
                    if (i_coun <= 0)//仓库不存在
                    {
                        #region 插入库位
                        str_sql = "insert into " + main.g_space + ".mst_location (" +
                  "inv_org,location_code,area_code,location_order,length,width,hight," +
                  "line_number,cubage_limit,weight_limit,number_limit,pallet_number," +
                  "location_flag,kind_flag,lock_flag,mix_sku,mix_lotno," +
                  "attribute1,attribute2,attribute3,attribute4,attribute5," +
                  "class_code1,class_code2,class_code3,class_code4,class_code5,memo,main_dist,made_time,maker,standby_flag1,putaway_flag,alloc_flag,safe_storage,standby_3) values (" +
                  "'" + main.g_org + "','" + dt.Rows[i]["库位号"].ToString().Trim() + "','" + dt.Rows[i]["区域号"].ToString().Trim() + "','0',0,0,0,"
                  + "0,0,0,10000000,1" +
                  ",'0','2','0','1','1',''" +
                      ",'','','',''," +
                      "'" + ((DataTable)cbx_class_code1.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                      ((DataTable)cbx_class_code2.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                      ((DataTable)cbx_class_code3.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                      ((DataTable)cbx_class_code4.DataSource).Rows[0]["class_code"].ToString().Trim() + "','" +
                      ((DataTable)cbx_class_code5.DataSource).Rows[0]["class_code"].ToString().Trim() + "','','A',";

                        if (main.dbtype == "SQL")
                        {
                            str_sql = str_sql + "getdate(),'";
                        }
                        else
                        {
                            str_sql = str_sql + " sysdate,'";
                        }

                        str_sql = str_sql + main.g_user + "','0','1','1',0,'')";
                        al.Add(str_sql);
                        #endregion
                        continue;
                    }
                    #endregion
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show("判断商品是否已经存在失败" + ee.Message);
                }

            }
            string[] str_sqllist = new string[al.Count];
            for (int i = 0; i < al.Count; i++)
            {
                str_sqllist[i] = al[i].ToString().Trim();
            }
            try
            {

                if (main.dbtype == "SQL")
                {
                    main.dbservice.Sql_exec_mutilsql(str_sqllist);
                }
                else
                {
                    main.dbservice.oracle_exec_mutilsql(str_sqllist);
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.Message);
            }


        }

        private void tb_number_limit_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == '\b')
            {

                e.Handled = false;
            }
        }

        private void tb_pallet_number_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == '\b')
            {

                e.Handled = false;
            }
        }

        private void tb_line_number_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
            if (e.KeyChar >= '0' && e.KeyChar <= '9' || e.KeyChar == '\b')
            {

                e.Handled = false;
            }
        }

        private void dvg_location_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            // 获取当前行的 Status 值
            string status = dvg_location.Rows[e.RowIndex].Cells["status_name"].Value.ToString();

            // 根据 Status 值设置整行的背景色
            switch (status)
            {
                
                case "停用":
                    dvg_location.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
                    break;
                
                default:
                    dvg_location.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
                    break;
            }
        }

        
    }
}